package com.mall.server.controller;

import com.mall.commons.R;
import com.mall.commons.exceotion.BusinessException;
import com.mall.commons.exceotion.ErrorResult;
import com.mall.server.service.OrderSettingService;
import com.tanhua.model.domain.OmsOrderSetting;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@CrossOrigin
@RestController
@RequestMapping("/orderSetting")
public class OrderSettingController {


    @Autowired
    private OrderSettingService orderSettingService;

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public R getOrderSetting(@PathVariable Long id) {
        OmsOrderSetting ood = orderSettingService.getOrderSetting(id);
        if (ood == null) {
            throw new BusinessException(ErrorResult.emptyError());
        }
        return R.success(ood);
    }

    /**
     * 修改数据
     *
     * @param oos
     * @return
     */
    @PostMapping("/update/{id}")
    public R updateSetting(@RequestBody OmsOrderSetting oos) {
        Boolean aBoolean = orderSettingService.updateSetting(oos);

        if (!aBoolean) {
            throw new BusinessException(ErrorResult.emptyError());
        }

        return R.success("操作成功");
    }
}
